package main

import (
	"gin_demo/auth"
	"gin_demo/controller"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func main() {

	r := gin.Default()

	config := cors.DefaultConfig()
	config.AllowAllOrigins = true
	config.AddAllowHeaders("Authorization")
	r.Use(cors.New(config))

	UserApi := r.Group("/api/user")

	UserApi.POST("/login", controller.Uc.UserLogin)
	UserApi.POST("/reg", controller.Uc.UserReg)

	AuthUserApi := UserApi.Group("auth")
	AuthUserApi.Use(auth.Ua.AuthMiddleware())
	AuthUserApi.GET("/getAllUser", controller.Uc.GetAllUser)
	AuthUserApi.POST("/DelUserByUsername", controller.Uc.DelUserByUsername)
	AuthUserApi.POST("/UpdatePasswordByUsername", controller.Uc.UpdatePasswordByUsername)

	err := r.Run(":8080")
	if err != nil {
		return
	}
}
